package m.jclecai.com.activity;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import m.jclecai.com.R;
import m.jclecai.com.base.BaseActivity;
import m.jclecai.com.utils.PreferenceUtil;

/**
 * Created by Dinosa on 2018/1/16.
 */

public class AppointmentOrderActivity extends BaseActivity {

    @BindView(R.id.tv_kefu_qq_number)
    TextView mTvKefuQqNumber;

    @BindView(R.id.tv_kefu_phone_number)
    TextView mTvKefuPhoneNumber;

    @Override
    protected int getContentView() {
        return R.layout.activity_appointment_order;
    }

    @Override
    protected void initView() {
        super.initView();
        leftOptionText("");
        setTitle("预约发单");
    }

    @Override
    protected void initData() {
        super.initData();
        //这里我们是需要读取本地的数据；

        mTvKefuPhoneNumber.setText("客服电话:\n"+ PreferenceUtil.readString(this,PreferenceUtil.KF_NUMBER,""));
        mTvKefuQqNumber.setText("QQ客服: \n"+PreferenceUtil.readString(this,PreferenceUtil.KF_QQ_NUMBER,""));

    }

    @OnClick(R.id.tv_kefu_qq_number)
    void onClickQQKefu() {
        //这里我们跳转qq的操作；
        if(isQQClientAvailable(this)){
            String url = "mqqwpa://im/chat?chat_type=wpa&uin="+PreferenceUtil.readString(this,PreferenceUtil.KF_QQ_NUMBER,"");
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
        }else{
            DisPlay("没有检测到qq客户端!!!");
        }
    }

    /**
     * 客服电话
     */
    @OnClick(R.id.tv_kefu_phone_number)
    void ServicePhone() {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:"+PreferenceUtil.readString(this,PreferenceUtil.KF_NUMBER,"")));
        startActivity(intent);
    }



    /**
     * 判断qq是否可用
     *
     * @param context
     * @return
     */
    public  boolean isQQClientAvailable(Context context) {
        final PackageManager packageManager = context.getPackageManager();
        List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
        if (pinfo != null) {
            for (int i = 0; i < pinfo.size(); i++) {
                String pn = pinfo.get(i).packageName;
                if (pn.equals("com.tencent.mobileqq")) {
                    return true;
                }
            }
        }
        return false;
    }
}
